package Bio::Rambam::Proteomics::Peptide;
use Moose;
use namespace::autoclean;
use Data::Dumper;


has 'identifier'		=>	(is =>'rw', isa=>'Str');
has 'sequence'			=>	(is=>'rw',isa=>'Str');
has 'charge'			=>	(is=>'rw',isa=>'Maybe[Int]');
has 'modifications'		=>	(is=>'ro',isa=>'ArrayRef[Bio::Rambam::Proteomics::Modification]',default=>sub{[]},);
has 'scores'			=> 	(is=>'rw',isa=>'ArrayRef[Bio::Rambam::Proteomics::Score]',default=>sub{[]},);
has 'protein_accessions'=> 	(is=>'rw',isa=>'ArrayRef[Str]',default=>sub{[]},clearer => 'clear_proteins',);


has 'decoy_peptide'		=>	(is=>'rw',isa=>'Bool',default=>0);
has 'number_proteins'	=>	(is=>'rw',isa=>'Int',default=>0);

my %mass_aa = (	A=>71.037114,V=>99.068414,L=>113.084064,I=>113.084064,P=>97.052764,M=>131.040485,
				F=>147.068414,W=>186.079313,G=>57.021464,S=>87.032028,T=>101.047679,C=>103.009185,
				Y=>163.06332,N=>114.042927,Q=>128.058578,D=>115.026943,E=>129.042593,H=>137.058912,
				K=>128.094963,R=>156.101111,U=>150.95363); # 20 proteinogenic aa's + selenoCys	



sub set_modification{
	my $self=shift;
	my %args = @_;
	my $mod=Bio::Rambam::Proteomics::Modification->new(	modLocation		=>	$args{modLocation},
														modmonodelta	=>	$args{modmonodelta},
									);
	push @{$self->modifications},$mod;
}

sub get_modifications{
	my $self=shift;
	my @modifications=@{$self->modifications};
	return @modifications;
}

sub set_score{
	my $self=shift;
	my %args = @_;
	my $score=Bio::Rambam::Proteomics::Score->new(	name	=>	$args{name},
													value	=>	$args{value},
									);
	push @{$self->scores},$score;
}

sub get_scores{
	my $self=shift;
	my @scores=@{$self->scores};
	return @scores;
}

sub set_protein{
	my $self=shift;
	my $protein_accession = shift;
	push @{$self->protein_accessions},$protein_accession;
	my $num_proteins=$self->number_proteins();
	$num_proteins++;
	$self->number_proteins($num_proteins);
	
}
sub get_proteins{
	my $self=shift;
	my @proteins=@{$self->protein_accessions};
	return @proteins;
}

sub calculate_molecular_mass{
	my $self=shift;
	my @aas=split '',$self->sequence;
	my $molecular_mass=0;
	foreach(@aas){
		return unless defined $mass_aa{$_};
		$molecular_mass+=$mass_aa{$_};
	}
	$molecular_mass+=18.0105647;
	my @modifications=$self->get_modifications;
	foreach(@modifications){
		$molecular_mass+=$_->modmonodelta;
		}
	return $molecular_mass;
}

sub modifications_string {
	my $self=shift;
	my @modifications_positions;
	for(my $i=0;$i<2+length($self->sequence);$i++){
		$modifications_positions[$i]=0;
	}
	my @mods=$self->get_modifications;
	foreach(@mods){
		$modifications_positions[$_->modLocation]=$_->modmonodelta;
	}
	return join '|',@modifications_positions;

}


__PACKAGE__->meta->make_immutable;